<style type="text/css">
   #form33 .layui-form-item .layui-input-inline{
        width: 80px;
    }
</style>
<div class="layui-form-item pt20 pl20 layui-form">
    <form class="layui-form"  action="{:url('mp/OutNodeProgress/confirmReturnGoods')}"   id="form33" >
        {foreach $list as $key=>$vo }
        <h2 class="layui-colla-title" style="clear: both;">订单{$vo.client_ordernum}，裁剪：{$vo.osStat.shicai_count}  件</h2>
         <div class="layui-form-item set_huihuo_{$vo.client_ordernum}" style="float: left;">
            <div class="layui-form-item">
                <label class="layui-form-label" >已回货数</label>
                <div class="layui-input-inline"></div>
            </div>
             {foreach $vo.osList as $key2=>$vo2 }
            <div class="layui-form-item">
                <label class="layui-form-label">{$vo2.size_name}</label>
                <div class="layui-input-inline">
                    {if $vo.batch_status==0 && $vo.batch_num>0}
                    <input type="text" name="return_num[{$vo.client_ordernum}][{$vo2.mid}]"  value="{$vo2.return_num}" readonly lay-verify="number|required" placeholder="输入数量" class="layui-input">
                    {else}
                    <input type="text" name="return_goods_num[{$vo.client_ordernum}][{$vo2.mid}]" onchange="return_goods_num_edit(this,'{$vo.client_ordernum}',{$vo2.mid})" value="{if $vo2.jiaohuo_count>0}{$vo2.jiaohuo_count}{else}0{/if}" {if $vo.readonly_return==1} readonly {/if}  lay-verify="number|required" placeholder="输入数量" class="layui-input set_num">
                    {/if}
                </div>
                <label class="layui-form-label">裁床数：{$vo2.shicai_count}</label>
                <input type="hidden" name="shicai_count[{$vo.client_ordernum}][{$vo2.mid}]" value="{$vo2.shicai_count}">
            </div>
             {/foreach}
        </div>
        {if $vo.batch_status==0 && $vo.batch_num>0}
        <div class="layui-form-item set_first_{$vo.client_ordernum}" style="float: left;clear: none;">
            <div class="layui-form-item">
                <label class="layui-form-label" style="font-weight: bold;color: #004b82!important;" >此批回货</label>
                <div class="layui-input-inline"></div>
            </div>
            {foreach $vo.osList as $key2=>$vo2 }
            <div class="layui-form-item">
                <label class="layui-form-label">{$vo2.size_name}</label>
                <div class="layui-input-inline">
                    <input type="text" name="return_goods_num[{$vo.client_ordernum}][{$vo2.mid}]" onchange="return_goods_num_edit(this,'{$vo.client_ordernum}',{$vo2.mid})" value="0" lay-verify="number|required" placeholder="输入数量" class="layui-input set_num">
                </div>
            </div>
            {/foreach}
        </div>
        {else}{/if}
        <div class="layui-form-item set_owe_{$vo.client_ordernum}" style="float: left;clear: none;">
            <div class="layui-form-item">
                <label class="layui-form-label" >欠数</label>
                <div class="layui-input-inline"></div>
            </div>
            {foreach  $vo.osList as $key2=>$vo2 }
            <div class="layui-form-item">
                <label class="layui-form-label">{$vo2.size_name}</label>
                <div class="layui-input-inline">
                    <input type="text" name="owe[{$vo.client_ordernum}][{$vo2.mid}]" data-option="{$vo2.mid}" value="{$vo2.owe}" lay-verify="number|required" placeholder="输入数量" readonly class="layui-input set_num">
                </div>
            </div>
            {/foreach}
        </div>

        <div class="layui-form-item" style="float: left;clear: none;">
            <label class="layui-form-label" >是否退料</label>
            <div class="layui-input-inline">
                <select name="sew_return_material_flag[{$vo.client_ordernum}]"  class="mimo-select group-id" style="width:80px;" lay-ignore="">
                    <option value="0" selected="">否</option>
                    <option value="1">是</option>
                </select>
            </div>
        </div>

        {/foreach}


        <div class="layui-inline fr" style="margin: 20px 20px;clear: both;">
            <button type="button" class="layui-btn layui-btn-normal" id="saveSewingform" style="background-color:#009688;">分批回货</button>
            <button type="button" class="layui-btn layui-btn-normal" id="submitSewingform">全部回货</button>
            <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
        </div>
    </form>
</div>


{include file="system@block/layui" /}
<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script type="text/javascript">
    var lock_return_goods_num_edit=0;
    layui.use([ 'element', 'layer', 'laytpl', 'tool','laydate','table','form','flow'], function() {
        var element = layui.element;
        var layer = layui.layer;
        var $ = layui.jquery;
        var form = layui.form;
        var laytpl = layui.laytpl,laydate=layui.laydate ,table = layui.table;
        var flow = layui.flow;

        //全部回货
        $(document).on('click','#submitSewingform',function(e){
            e.stopPropagation();
            $.ajax({
                type: "POST",
                url: "{:url('mp/OutNodeProgress/confirmReturnGoodsV2')}"+"?type_name=sewing_v2",
                data: $('#form33').serialize() ,
                dataType:"json",
                success: function(res){
                    if (res.code == 1) {
                        window.parent.location.reload();
                        parent.layer.closeAll();
                    } else {
                        layer.msg(res.msg, {icon: 2,anim: 6});
                    }
                }
            });
            return false;
        });
        //分批回货
        $(document).on('click','#saveSewingform',function(e){
            e.stopPropagation();
            $.ajax({
                type: "POST",
                url: "{:url('mp/OutNodeProgress/confirmReturnGoodsV2')}"+"?type_name=sewing_v2_batch",
                data: $('#form33').serialize() ,
                dataType:"json",
                success: function(res){
                    if (res.code == 1) {
                        window.parent.location.reload();
                        parent.layer.closeAll();
                    } else {
                        layer.msg(res.msg, {icon: 2,anim: 6});
                    }
                }
            });
            return false;
        });
    });

    //回货数 设置
    function return_goods_num_edit(obj,client_ordernum,mid) {
        //1,查检是否可以输入数据，第一批回货要为0才行
        // $('.set_first_'+client_ordernum).find('.set_num').each(function(i){
        //     if(parseInt($(this).val())>0){
        //         var layer = layui.layer;
        //         layer.confirm('重置第一批回货为0', {btn: ['确定','取消']}, function(index){
        //             $('.set_first_'+client_ordernum).find('.set_num').val(0);
        //             set_owe_all(client_ordernum);
        //             layer.close(index);
        //         }, function(index){
        //             $(obj).val(0);
        //             layer.close(index);
        //         });
        //     }
        // });
        set_owe_all(client_ordernum);
    }
    //第一批回货 设置
    function return_goods_num_edit_v2(obj,client_ordernum,mid) {
        //1,查检是否可以输入数据，回货数要为0才行
        $('.set_huihuo_'+client_ordernum).find('.set_num').each(function(i){
            if(parseInt($(this).val())>0){
                var layer = layui.layer;
                layer.confirm('重置回货数为0', {btn: ['确定','取消']}, function(index){
                    $('.set_huihuo_'+client_ordernum).find('.set_num').val(0);
                    set_owe_all(client_ordernum);
                    layer.close(index);
                }, function(index){
                    $(obj).val(0);
                    layer.close(index);
                });
            }
        });
        set_owe_all(client_ordernum);
    }

    //欠数 设置
    function set_owe_all(client_ordernum) {
        $('.set_owe_'+client_ordernum).find('.set_num').each(function(i){
            var mid=$(this).attr('data-option');
            var shicai_count=($('[name="shicai_count['+client_ordernum+']['+mid+']"]').val()) ;
            var return_goods_num=($('[name="return_goods_num['+client_ordernum+']['+mid+']"]').val());
            var return_num=($('[name="return_num['+client_ordernum+']['+mid+']"]').val());
            shicai_count=!shicai_count?0:parseInt(shicai_count);
            return_goods_num=!return_goods_num?0:parseInt(return_goods_num);
            return_num=!return_num?0:parseInt(return_num);
            $('[name="owe['+client_ordernum+']['+mid+']"]').val(shicai_count-return_goods_num-return_num);
        });
    }
</script>